#include "network.h"

#include <sys/types.h>
#include <ifaddrs.h>
#include <string.h>
#include <net/if.h>

bool Network::checkInterface(char *interfaceName)
{
    bool result = false;
    struct ifaddrs *ifs = 0;

    if(getifaddrs(&ifs)!=-1) {
        struct ifaddrs *interface = ifs;

        while(interface) {
            if(!strcmp(interface->ifa_name,interfaceName)) {
                if( (interface->ifa_flags & IFF_UP) && (interface->ifa_flags & IFF_RUNNING) ) {
                    result = true;
                }
                break;
            }
            interface = interface->ifa_next;
        }
    }

    if(ifs) {
        freeifaddrs(ifs);
    }

    return result;
}
